﻿// contntesManager
(function ($, undefined) {

    // define the name of the UI component
    var ui_name = "ajaxBusyProgress"

    // initialize object
    var cm = $.ajaxBusyProgress = {

        // default values
        defaults: {

        },

        setDefaults: function (defaultOptions) {
            this.defaults = $.extend({}, this.defaults, defaultOptions);
        }
    };

    $.fn.ajaxBusyProgress = function (options) {

        // method calling
        if (typeof options == 'string') {
            var args = Array.prototype.slice.call(arguments, 1),
			    res;
            this.each(function () {
                var data = $.data(this, ui_name);
                if (data) {
                    var meth = data[options];
                    if (meth) {
                        var r = meth.apply(this, args);
                        if (res === undefined) {
                            res = r;
                        }
                    }
                }
            });
            if (res !== undefined) {
                return res;
            }
            return this;
        }

        // initialize options
        options = $.extend({}, cm.defaults, options);

        this.each(function () {
            var _self = this;

            initAjaxBusyProgress();


            // initialize callback
            for (var key in options) {
                var value = options[key];
                if (typeof value == 'function') {
                    // bind callbacks
                    $(_self).bind(key, value);
                }

            }

            /* Private Methods
            -----------------------------------------------------------------------------*/
            function initAjaxBusyProgress() {
                var prgressDomStr = '<div class="__ajax_progress">' +
                                     '<div style="margin-left: 10px; font-size: 12px;">处理中...</div>' +
                                     '<img alt="progress" width="350" height="35" src="../../Content/images/ajax_loader_progress.gif" />' +
                                '</div>';

                var progressDom = 
                    $(prgressDomStr)
                    .attr('class', $(_self).attr('class'));
                $(_self).hide().after(progressDom);
            };




            /* Callback Triggers
            -----------------------------------------------------------------------------*/




            /* Public Methods
            -----------------------------------------------------------------------------*/

            var publicMethods = {
                option: function (name, value) {
                    if (value === undefined) {
                        return options[name];
                    }
                    options[name] = value;
                },
                reset: function () {
                    $(_self).show()
                        .next().remove()
                }



                // @other public methods
            };

            $.data(this, ui_name, publicMethods);


            // @private methods


            // define callback triggers

            //function select() {
            //    var val = 12345;
            //    $(_self).trigger('select', val);
            //}

        });

        return this;
    };

    // @static methods
    var resetHtml;

})(jQuery);
